// 输入框组件实例

import { assignInWith } from 'lodash'
import type {
    dateRangeConfigType,
    inputConfigType,
    tableConfigType
} from '../../../../../types/index'
import BaseEntity from '../../BaseEntity'
import { uid } from 'uid'
import type { configType, slotFormConfigType } from '../../BaseEntity'
import { entityType } from '../..'
import type { TableColumnData, TableData } from '@arco-design/web-vue'
import RoleApi from '@/api/system/role/RoleApi'
import UserApi from '@/api/user/UserApi'



export default class TableEntity extends BaseEntity {
    constructor(config: configType, slotFormConfig: slotFormConfigType) {
        let baseConfig: configType = {
            class: ['draggable-form-hover'],
            style: { width: '100%' },
            field: 'Table_' + uid(4),
            label: "明细表",
            required: false,
            hideLabel: false
        }
        let baseSlotFormConfig:slotFormConfigType = {
          modelValue:[] , //该自定义组件中暂未使用该字段 默认所有组件都需要定义该字段
          tableColumns:[],
        }
        let componentConfig: tableConfigType = {
          tableColumns:{
            type:'optionsSetting',
            formItemConfig: {
                label: '表格列'
            },
            formItemElement: {
                modelValue: [],
            }
          },
            required: {
              type:'switch',
              formItemConfig:{
                label:'必填',
              },
              formItemElement:{
                 modelValue:false,
              }
            },
            label: {
              type:'input',
              formItemConfig:{
                label:'标签名称',
              },
              formItemElement:{
                 modelValue:'',
                 placeholder:'请输入',
              }
            },
        }

        super(
            entityType.table,
            assignInWith(baseConfig, config),
            assignInWith(baseSlotFormConfig, slotFormConfig),
            componentConfig
        )



        this.initSlotFormConfig()
    }
    initSlotFormConfig() {
        //初始化表单组件可配置项 因为表单组件可配置项是根据表单组件所拥有得属性来定义的 配置项得值需要对应初始化实例得对应属性得值
        Object.keys(this.componentConfig).forEach(key => {
            if (this.slotFormConfig[key]) {
                this.componentConfig[key].formItemElement.modelValue = this.slotFormConfig[key]
            }
        })
    }

}

